<template>
	<view class="box">
		<view class="head">
			<image src="@/static/icon/bj.jpg"></image>
			<text class="title">
				<text style="color: white;">积分</text>
				<text style="color: yellow;">兑</text>
				<text style="color: white;">好礼</text>
			</text>
			<mysearch @click="gotoSearch"></mysearch>
		</view>
		<view class="content">
			<view class="ad">
				<uni-icons type="sound-filled" size="25" color="#bc8dd4" style="margin-left: 2px;"></uni-icons>
				<text class="ad-content">{{adText}}</text>
			</view>
			<view class="classify">
				<view v-for="(item, index) in classify" :key="index" style="text-align: center;" @click="tosettings(index)">
					<view class="classify-icon">
						<image src="item.icon" mode="aspectFill"
							style="width: 40px;height: 40px;"></image>
					</view>
					<view class="classify-text">{{item.title}}</view>
				</view>
			</view>
			<view class="gift">
				<image src="@/static/icon/gift.jpg"></image>
				<view class="gift_text1">{{gift_text1}}</view>
				<view class="gift_text2">{{gift_text2}}</view>
				<button>立即查看</button>
			</view>
			<view class="options">
				<view class="options_list_tab">
					<view class="options-text" v-for="(item, index) in options" :key="index"
						:class="{ active: selectedIndex === index, 'selected-tab': selectedIndex === index }"
						@click="selectTab(index)">
						{{item}}
					</view>
					<view class="underline" v-show="selectedIndex === index"></view>
				</view>
				<view class="product-list" v-if="selectedIndex==0">
					<view v-for="(product, index) in product1" :key="index" class="product-item">
						<view class="product">
							<view class="tu">
								<image :src="product.image" mode="aspectFill" />
							</view>
							<text class="product-name">{{product.name}}</text>
							<text class="product-price">{{product.price}}积分</text>
							<button>立即购买</button>
						</view>
					</view>
				</view>
				<view class="product-list" v-if="selectedIndex==1">
					<view v-for="(product, index) in product2" :key="index" class="product-item">
						<view class="product">
							<view class="tu">
								<image :src="product.image" mode="aspectFill" />
							</view>
							<text class="product-name">{{product.name}}</text>
							<text class="product-price">{{product.price}}积分</text>
							<button>立即购买</button>
						</view>
					</view>
				</view>
				<view class="product-list" v-if="selectedIndex==2">
					<view v-for="(product, index) in product3" :key="index" class="product-item">
						<view class="product">
							<view class="tu">
								<image :src="product.image" mode="aspectFill" />
							</view>
							<text class="product-name">{{product.name}}</text>
							<text class="product-price">{{product.price}}积分</text>
							<button>立即购买</button>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// import {GetRedis} from '@/api/jiekou.js'
	export default {
		data() {
			return {
				title: 'Hello',
				adText: '每位客户每月限购2件，每天上午10：00更新库存',
				classify: [{
						icon: '家电.png',
						title: '智能家电',
					},
					{
						icon: '运动.png',
						title: '健康运动',
					},
					{
						icon: '耳机.png',
						title: '娱乐出行',
					},
					{
						icon: '床.png',
						title: '日用家居',
					}
				],
				gift_text1: '积分有赏',
				gift_text2: '专享1元+积分兑大牌',
				selectedIndex: 0,
				options: ['15万积分以下', '15万-45万积分', '45万积分以上'],
				product1: [{
						image: 'apple.jpg',
						name: '【兑好礼】苹果',
						price: '￥1.00+16350'
					},
					{
						image: 'apple.jpg',
						name: '【兑好礼】苹果',
						price: '16350'
					},
					{
						image: 'apple.jpg',
						name: '【兑好礼】苹果',
						price: '1116350'
					},
				],
				product2: [{
						image: 'apple.jpg',
						name: '【兑好礼】苹果',
						price: '￥1.00+16350'
					},
					{
						image: 'apple.jpg',
						name: '【兑好礼】苹果',
						price: '16350'
					},
				],
				product3: [{
						image: 'apple.jpg',
						name: '【兑好礼】苹果',
						price: '￥1.00+16350'
					},
					{
						image: 'apple.jpg',
						name: '【兑好礼】苹果',
						price: '16350'
					},
					{
						image: 'apple.jpg',
						name: '【兑好礼】苹果',
						price: '1116350'
					},
					{
						image: 'apple.jpg',
						name: '【兑好礼】苹果',
						price: '￥1.00+16350'
					},
				],
			}
		},
		onLoad() {
			this.getClassify() 
		},
		methods: {
			gotoSearch() {
				uni.navigateTo({
					url: '/pages/search/search'
				})
			},
			gotoGifts() {
				// 跳转到礼品页面的逻辑
				// 例如：this.$router.push('/gifts')
			},
			tosettings(index){
				if(index=1){
					uni.navigateTo({
						url: '/pages/settings/settings'
					})
				}
			},
			selectTab(index) {
				this.selectedIndex = index;
			},
			async getData() {
				const res = await getAddAction({})
			},
			async getClassify(){
				const res = await GetRedis({Key:'classify_test'})
				if(res.Status == 'success'){
					console.log(res.Data);
					// return res.Data
					// this.classify = res.Data
				}
			},
		}
	}
</script>

<style>
	.head {
		position: relative;
		z-index: 1;
		height: 120px;
	}

	.head image {
		width: 100%;
		height: 120px;
		position: absolute;
		z-index: -1;
	}

	.title {
		position: relative;
		font-size: 20px;
		top: 30px;
		left: 28px;
	}

	.my-search-box {
		bottom: 10px;
		margin-top: 80px;
	}

	.content {
		/* display: flex;
		flex-direction: column;
		align-items: center; */
		/* justify-content: center; */
		width: 90%;
		margin: auto;
	}

	.ad {
		display: flex;
		align-items: center;
		height: 25px;
		font-size: 13px;
		border: 1px;
		border-radius: 10px;
		background-color: #ecebf3;
		margin-top: 10px;
	}

	.classify {
		/* height: 200px; */
		display: flex;
		align-items: center;
		justify-content: space-around;
		margin-top: 20px;
	}

	.classify-icon {
		width: 55px;
		height: 55px;
		border: 1px;
		border-radius: 100%;
		background-color: #f6f6f6;
		display: flex;
		align-items: center;
		justify-content: space-around;
	}

	.classify-text {
		margin-top: 10px;
	}

	.gift {
		position: relative;
		z-index: 1;
		height: 150px;
		margin-top: 20px;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
	}

	.gift image {
		width: 100%;
		height: 150px;
		position: absolute;
		z-index: -1;
		border-radius: 10px;
	}

	.gift_text1 {
		margin-left: 20px;
		margin-top: 10px;
	}

	.gift_text2 {
		margin-left: 20px;
	}

	.gift button {
		margin: 0;
		width: 110px;
		height: 30px;
		display: flex;
		align-items: center;
		margin-left: 20px;
		margin-bottom: 10px;
		border-radius: 20px;
		background-color: #f96058;
		color: white;
	}

	.options {
		/* display: flex; */
		/* flex-direction: column; */
		margin-top: 10px;
	}

	.options_list_tab {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 10px;
		box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
		margin-bottom: 10px;
	}

	.options-text {
		color: #000;
		cursor: pointer;
		position: relative;
		padding-bottom: 2px;
	}

	.options-text.active {
		color: red;
	}

	.underline {
		position: absolute;
		bottom: 0;
		left: 0;
		width: 20%;
		height: 2px;
		background-color: red;
		transition: width 0.3s;
	}

	.selected-tab .underline {
		width: 100%;
	}

	.product-list {
		display: flex;
		flex-wrap: wrap;
	}

	.product-item {
		padding: 10px;
		border: 1px;
		display: flex;
		width: calc(100% / 3);
		box-sizing: border-box;
	}

	.product {
		display: flex;
		flex-direction: column;
	}

	.tu {
		width: 100%;
		height: 100px;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.tu image {
		width: 70px;
		height: 70px;
		padding: 10px;
		margin-bottom: 10px;
	}

	/* .product-name {
		font-weight: bold;
	} */

	.product-price {
		color: #dc4341;
		font-size: 10px;
		margin-top: 5px;
		margin-bottom: 5px;
	}

	.product-item button {
		margin-top: 10px;
		margin: 0;
		width: 65%;
		height: 18px;
		font-size: 8px;
		border-radius: 20px;
		color: white;
		background-color: #ed150e;
	}
</style>